package com.test.ai.controller;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created with IntelliJ IDEA.
 *
 * @description:
 * @author: liuziyang
 * @since: 2025/8/18 12:40
 * @modifiedBy:
 * @version: 1.0
 */
@RestController
public class ChatClientController {
  private final ChatClient chatClient;

  public ChatClientController(@Qualifier("openAiChatClient") ChatClient chatClient) {
    this.chatClient = chatClient;
  }

  @GetMapping("/chat")
  public String chat(@RequestParam(value = "msg", defaultValue = "你是谁") String msg) {
    return chatClient.prompt().user(msg).call().content();
  }
}
